import axiosInstance from './axiosInstance';

// 创建新的反馈
export const createFeedback = (feedbackData) => {
    return axiosInstance.post('/api/feedback', feedbackData);
};

// 获取所有反馈
export const getAllFeedback = () => {
    return axiosInstance.get('/api/feedback');
};

// 获取特定用户的反馈
export const getUserFeedback = () => {
    return axiosInstance.get('/api/feedback/user');
};

// 获取特定类型的反馈
export const getFeedbackByType = (type) => {
    return axiosInstance.get(`/api/feedback/type/${type}`);
};

// 更新反馈
export const updateFeedback = (id, feedbackData) => {
    return axiosInstance.put(`/api/feedback/${id}`, feedbackData);
};

// 删除反馈
export const deleteFeedback = (id) => {
    return axiosInstance.delete(`/api/feedback/${id}`);
};

// 搜索反馈
export const searchFeedback = (keyword) => {
    return axiosInstance.get(`/api/feedback/search`, { params: { keyword } })
        .then(response => {
            return response;
        })
        .catch(error => {
            if (error.response && error.response.status === 401) {
                throw new Error('未授权，请重新登录');
            } else {
                console.error('搜索反馈时发生错误:', error);
                throw new Error('搜索反馈失败');
            }
        });
};